<template>
  <div>
    <h1>作业2</h1>
    <ul>
      <li v-for="(item, index) in list" :key="item.id">
        {{ item.num }}<button @click="deleteFn(index)">删除</button>
      </li>
    </ul>
    <button @click="addFn">新增</button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      list: [{ num: 1, id: 1 }],
    }
  },
  methods: {
    addFn() {
      this.list.push({
        num: Math.floor(Math.random() * 100),
        id: this.list.length + 1,
      })
    },
    deleteFn(id) {
      this.list.splice(id, 1)
    },
  },
}
</script>

<style></style>
